package com.zoo.diannaopeijian.controller.purchase;

import com.zoo.diannaopeijian.controller.BaseController;
import com.zoo.diannaopeijian.domain.PurchaseChannel;
import com.zoo.diannaopeijian.service.PurchaseChannelService;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 入货渠道控制器
 */
@Controller
@RequestMapping("/purchaseChannel")
public class PurchaseChannelController extends BaseController {
    @Resource
    private PurchaseChannelService purchaseChannelService;

    @GetMapping(value = "/pages/{pageName}")
    public String pageRoute(@PathVariable String pageName) {
        return "purchase/purchaseChannel/" + pageName;
    }

//    @RequestMapping("SupplyChannelManaPage")
//    public String SupplyChannelManaPageRoute() {
//        return "entry/supplychannel/SupplyChannelManaPage";
//    }
//
//    @RequestMapping("SupplyChannelAddPage")
//    public String SupplyChannelAddPageRoute() {
//        return "entry/supplychannel/SupplyChannelAddPage";
//    }
//
//    @RequestMapping("SupplyChannelUpdatePage")
//    public String SupplyChannelUpdatePage() {
//        return "entry/supplychannel/SupplyChannelUpdatePage";
//    }

    @GetMapping("/")
    public ResponseEntity<List<PurchaseChannel>> purchaseChannelGet() {
        return ResponseEntity.ok(purchaseChannelService.getAllPurchaseChannel());
    }

    @PostMapping("/")
    public ResponseEntity<String> purchaseChannelPost(PurchaseChannel purchaseChannel) {
        return ResponseEntity.ok(purchaseChannelService.addPurchaseChannel(purchaseChannel) ? success : fail);
    }

    @PutMapping("/")
    public ResponseEntity<String> purchaseChannelPut(PurchaseChannel purchaseChannel) {
        return ResponseEntity.ok(purchaseChannelService.updatePurchaseChannel(purchaseChannel) ? success : fail);
    }

    @DeleteMapping("/{purchaseChannelId}")
    public ResponseEntity<String> purchaseChannelDelete(@PathVariable Integer purchaseChannelId) {
        return ResponseEntity.ok(purchaseChannelService.deletePurchaseChannelById(purchaseChannelId) ? success : fail);
    }
}
